<template>
	<div class="page">
		<div class="degnluTxt">
			<!--加载中，请稍等。。。-->
		</div>
	</div>
</template>
<script type="text/ecmascript-6">
	import { mapState, mapMutations } from "vuex";
	export default {
		computed: {
			...mapState({
				//          addSellForm  : state => state.UserModule.sellAddData
				tabMenuData: state => state.AppModule.tabMenuData,
				tabMenuData1: state => state.AppModule.tabMenuData1,
				tabMenuData2: state => state.AppModule.tabMenuData2,

			})
		},
		mounted() {
			document.title = "加载中...";
			
//			if(localStorage.getItem('openids')){
//				console.log('已授权登录账号')
//				var newArr = [];
//				if(this.$userData.getIsManager() == 0 || this.$userData.getOsType() == 2 || this.$userData.getOsType() == 3) {
//					//更新底部tab
//					this["AppModule/updateTabNumber"](this.tabMenuData2);
//				} else {
//					//更新底部tab
//					this["AppModule/updateTabNumber"](this.tabMenuData1);
//				}
//
//				this.$easyUtil.tabSelectedGoPage(this, 0)
//				
//			}else{
//				
//				console.log('未授权登录账号')
				this.shouquan();
				
//			}
		},
		data() {
			return {}
		},
		methods: {
			...mapMutations(["AppModule/updateTabNumber"]),
			//获取get参数
			getQueryVariable(variable) {
				var query = window.location.search.substring(1);
				var vars = query.split("&");
				for(var i = 0; i < vars.length; i++) {
					var pair = vars[i].split("=");
					if(pair[0] == variable) {
						return pair[1];
					}
				}
				return(false);
			},
			//登录授权拉取资料
			shouquan() {
				var that = this;
				var urlstr = window.location.href;
				var ss = urlstr.split('#/'); //当前页面地址
				
				var arr = urlstr.split('?')[1].split('#')[0].split('&');
				
				var urlCode = arr[0].split('=')[1] //获取返回用户code
				var stateVal = arr[1].split('=')[1];
				
//				var urlCode = this.$route.query.code; //获取返回用户code
//				var stateVal = this.$route.query.state;
				stateVal = stateVal.split('XXX');
				console.log(stateVal)
				

				if(stateVal[0] == 'linshiputong') {

					var urla = "/weixin/getOpenId/code/" + urlCode;
					console.log(urla)
					this.$easyUtil.startLoading(this);
					this.$http.getHttp(
						urla,
						rs => {
							console.log(rs)

							//普通登录保存OPENID
							console.log('普通登录保存OPENID普通登录保存OPENID普通登录保存OPENID普通登录保存OPENID')

							//保存当前手机临时openid用来支付等操作uids
							localStorage.setItem("openids", rs.openid);

							var params = {
								u_id: stateVal[1],
								u_openid: rs.openid,
								update_where: 'u_id'
							}

							that.$http.postHttp(that.$API.userUpdate, params, (rs1) => {

								that.$easyUtil.endLoading(that)
								that.$easyUtil.successToast(that, '登录成功');
								console.log('管理员OPENID绑定完成')

								var newArr = [];
								if(that.$userData.getIsManager() == 0 || that.$userData.getOsType() == 2 || that.$userData.getOsType() == 3) {
									//更新底部tab
									that["AppModule/updateTabNumber"](that.tabMenuData2);
								} else {
									//更新底部tab
									that["AppModule/updateTabNumber"](that.tabMenuData1);
								}

								that.$easyUtil.tabSelectedGoPage(that, 0)

							})

						})

				} else {
					console.log('没有后缀的页面')
					history.go(-1);
				}

			}
		}
	}
</script>

<style>
	.wxloging {
		margin: 0 auto;
		margin-top: 45%;
		text-align: center;
		width: 140px;
		height: 67px;
		/*width: 50px;
		height: 50px;*/
	}
	
	.wxloging img {
		width: 100%;
		height: 100%;
		object-fit: cover;
	}
	
	.degnluTxt {
		margin-top: 30px;
		text-align: center;
	}
</style>